<%--
  Created by IntelliJ IDEA.
  User: 11875
  Date: 2021/10/18
  Time: 10:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>宿舍管理系统</title>
    <link rel="stylesheet" href="/css/homepageheder.css">
    <link rel="stylesheet" href="/css/tradmilsit.css">
    <link rel="stylesheet" href="/css/details.css">
    <link rel="stylesheet" href="/css/bootstrap.css">
</head>

<body>
<!-- 头部 -->
<div class="heder">
    <div class="title">
        <div class="title_t">
            <span>宿 舍 管 理 系 统</span>
        </div>
        <div class="title_r">
            欢迎您！！！
            <c:if test="${user.typeid == 1}">
                班主任老师
            </c:if>
            <c:if test="${user.typeid == 2}">
                班主任老师
            </c:if>
            ${user.uname}
            <span>|</span>
            <a href="javascript:history.go(-1)">返回上一页</a>
            <span>|</span>
            <a href="/user/main">返回主页</a>
            <span>|</span>
            <a href="/user/updatepasswordpage">修改密码</a>
            <span>|</span>
            <a href="/logout">退出</a>
        </div>
    </div>
</div>

<div class="hr"></div>

<div id="content" class="container clearfix">
    <h2>学生详情</h2>
    <ul class="col-md-6">
        <li>姓名：${student.sname}</li>
        <li>所属年级：${classes.cgrade}级</li>
        <li>生日：<fmt:formatDate value="${student.birthday}" pattern="yyyy-MM-dd"></fmt:formatDate></li>
        <li>状态：
            <span>${student.cstatus==1?"在读":"毕业"}</span>
            <a href="#" id="changestustatus" data-sid="${student.sid}" data-cstatus="${student.cstatus}">修改状态</a>
        </li>
        <li>父母姓名：${student.parentname}</li>
    </ul>
    <ul class="col-md-6">
        <li>性别：${student.sex}</li>
        <li>所属班级：${classes.cname}</li>
        <li>电话：${student.mobile}</li>
        <li>家庭地址：${student.address}</li>
        <li>父母电话：${student.parentmobile}</li>
    </ul>
</div>


<script src="/js/jquery-3.6.0.min.js"></script>
<script src="/js/bootstrap.js"></script>


<script>
    $(function () {
        $("#changestustatus").on("click", function () {
            if (!window.confirm("您是否需要修改当前学生的状态？"))
                return false;
            let ssid = this.dataset.sid;
            let scstatus = this.dataset.cstatus == 1 ? 0 : 1;

            $.ajax({
                type: "get",   // 请求方式
                url: "/student/ajaxchangestatus",   // 请求的url
                data: {
                    sid: ssid,
                    cstatus: scstatus
                },   // 请求参数，json格式写法
                //dataType: "json",  //  默认值为text文本
                success: function (msg) {  //  成功返回，接收数据结果并处理
                    console.log(msg);
                    if (msg === "ok") { //  返回ok，代表修改成功，则改变显示的参数以及文字
                        $("#changestustatus").attr("data-cstatus", scstatus);
                        $("#changestustatus").prev("span").html(scstatus == 1 ? "在读" : "毕业");
                    }
                }
            });

            return false;
        });
    });
</script>
</body>

</html>